package com.learn.exchange;

import com.learn.utils.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;

/**
 * @author DJJ_F
 * @version 1.0
 * @date 2025/08/23
 * @description ch05 交换机
 * 扇出交换机
 */
public class TopicEmit {
    public static final String EXCHANGE_NAME = "topic_exchange";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        // 声明交换机
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC);

        System.out.println("emit ready-------------------");
        List<String> list = Arrays.asList("quick.orange.rabbit",
                "azy.orange.elephant",
                "quick.orange.fox",
                "lazy.brown.fox",
                "lazy.pink.rabbit",
                "quick.brown.fox",
                "quick.orange.male.rabbit",
                "lazy.orange.male.rabbit");
        for (int i = 0; i < list.size(); i++) {
            String msg = "msg0" + i;
            channel.basicPublish(EXCHANGE_NAME,
                    list.get(i),
                    null,
                    msg.getBytes(StandardCharsets.UTF_8));
        }
    }
}
